共有 "basic", "image", "list" 三種類型
manifest.json
{
"manifest_version": 2,
"name": "ironman6",
"version": "1.0",
"browser_action": {
"default_popup": "index.html"
},
"permissions": [
"notifications"
]
}
index.html
<title>ironman6</title>
<style>body {width: 500px;}</style>
<button id="showBasic">Show Basic</button><br/>
<button id="showImage">Show Image</button><br/>
<button id="showList">Show List</button>
<script src="app.js"></script>
app.js
window.addEventListener("load", function() {
document.querySelector("#showBasic").addEventListener("click", showBasic);
document.querySelector("#showImage").addEventListener("click", showImage);
document.querySelector("#showList").addEventListener("click", showList);
chrome.notifications.onButtonClicked.addListener(notificationBtnClick);
});
var testImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAVUklEQVR4nO1dW4xkV3Vde59zH/Xq10z3zHg82GP8iO3EEGRZjkWIE9lEUeIRIh8RIhJffCRKyIdlKRL5yV8iFAL5SD4IEihECopIhBUHsJADgrwcHkbGBgzMGD9meqann9Vdj3vP2Tsfp27V7Z7qnq7qx4xFL6m7bt2qvvectfdZe99z79kNHOEIRzjCEY5whCMc4QhHOMIRjnCEIxwaaB+OkQI4DqABoLJPx7yZoQDaAJoArgLo7OVgeyGLAdzy5JNPPvShD33o/SdPnnxXvV6/h5kZAIi2P/TWz3b67n5DVXd8P+yz8quIyPr6+o/m5+e/85nPfOZfPvGJTzwP4CIAGac94/Z8CsDsN7/5zT94xzve8YfGmAQIRKrqJkK32x72fref7Ra7IXfY+522ix8A8N53X3jhhb999NFH/w7AAoCVUds4Ti/TEydOvPP555//q2PHjj2yE6mjkn+QI2GYMUY1QtkA5c+Xlpb+6+GHH37y8uXL3wXQHaVdPMqXe5h99tlnPzIzM/PI1oaMSz4RXZf84js7/ezm76/Xjp22hx1DVTE9Pf3IM88880cA5nZsxBDYEb9f+ehHP/rI7bff/ntbP3Be83/44n9/4wtf/r/LL7z0eu69CI2pizcbFGBjmN9575no/b/1rhMffOLhX7WGovLIOHv27AeeeuqpL37sYx9bwAiBedQxf+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ZBuvoEgP0c4whGOcIQjHOEIRzjCEY5whLcK/h+oSG1yJABe1AAAAABJRU5ErkJggg==';
function showBasic(){
chrome.notifications.create(
'Notifier' + Date.now(), {
type: 'basic',
iconUrl: testImg,
title: 'Ironman6',
message: 'Day 14',
buttons: [{
title: 'Yes',
iconUrl: testImg
},{
title: 'No',
iconUrl: testImg
}]
},
function(notificationId) {
console.log(notificationId);
}
);
}
function showList(){
chrome.notifications.create(
'Notifier' + Date.now(), {
type: 'list',
iconUrl: testImg,
title: 'Ironman6',
message: 'Day 14',
items: [{ title: "Item1", message: "Day 15"},
{ title: "Item2", message: "Day 16"},
{ title: "Item3", message: "Day 17"},
{ title: "Item2", message: "Day 18"},
{ title: "Item3", message: "Day 19"}]
},
function(notificationId) {
console.log(notificationId);
}
);
}
function showImage(){
chrome.notifications.create(
'Notifier' + Date.now(), {
type: 'image',
iconUrl: testImg,
title: 'Ironman6',
message: 'Day 14',
imageUrl: testImg
},
function(notificationId) {
console.log(notificationId);
}
);
}
function notificationBtnClick(notID, iBtn) {
console.log("The notification '" + notID + "' had button " + iBtn + " clicked");
}
要注意的是圖片只能使用 本地資源(local resource) 或是 data URL.